<template>
	<view class="Layout pageBg">
		<custom-nav-bar title="推荐"></custom-nav-bar>
		<view class="banner">
			<swiper circular indicator-dots indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff"
				autoplay>
				<swiper-item v-for="item in bannerList" :key="item._id">

					<navigator v-if="item.target =='miniProgram'" url="" class="like" target="miniProgram">
						<image :src="item.picurl" mode="aspectFill"></image>
					</navigator>

					<navigator v-else :url="`/pages/claaslist/claaslist?${item.url}`" class="like">
						<image :src="item.picurl" mode="aspectFill"></image>
					</navigator>
				</swiper-item>
			</swiper>
		</view>

		<view class="notice">
			<view class="left">
				<uni-icons type="sound-filled" size="20"></uni-icons>
				<text class="text"> 公告</text>
			</view>
			<view class="center">
				<swiper vertical autoplay interval="1500" duration="300" circular>
					<swiper-item v-for="item in wallNewsList " :key="item">
						{{item.title}}
					</swiper-item>
				</swiper>
			</view>
			<view class="rigth">
				<uni-icons type="right" size="16" color="#333"></uni-icons>
			</view>
		</view>

		<view class="horoscope">
			<common-title>
				<template #name> 每日星运</template>
				<template #custom>
					<navigator url="/pages/horoscope/horoscope" open-type="reLaunch" class="date">详情</navigator>
				</template>
			</common-title>
			<view class="content">
				<view class="fortune">
					<view v-if="horoscopeDay.star === 'baiyang' ">白羊座今日运势</view>
					<view v-if="horoscopeDay.star === 'jinniu' ">金牛座今日运势</view>
					<view v-if="horoscopeDay.star === 'shuangzi' ">双子座今日运势</view>
					<view v-if="horoscopeDay.star === 'juxie' ">巨蟹座今日运势</view>
					<view v-if="horoscopeDay.star === 'shizi' ">狮子座今日运势</view>
					<view v-if="horoscopeDay.star === 'chunv' ">处女座今日运势</view>
					<view v-if="horoscopeDay.star === 'tiancheng' ">天秤座今日运势</view>
					<view v-if="horoscopeDay.star === 'tianxie' ">天蝎座今日运势</view>
					<view v-if="horoscopeDay.star === 'sheshou' ">射手座今日运势</view>
					<view v-if="horoscopeDay.star === 'mojie' ">摩羯座今日运势</view>
					<view v-if="horoscopeDay.star === 'shuiping' ">水瓶座今日运势</view>
					<view v-if="horoscopeDay.star === 'shuangyu' ">双鱼座今日运势</view>
				</view>
				<view class="exponent">
					<view class="synthe">
						<view class="index">
							<text>综合指数:</text>
							<uni-rate readonly touchable :value="Daydata.summary_star" size="22" />
						</view>

						<view class="index">
							<text>爱情指数:</text>
							<uni-rate readonly touchable :value="Daydata.love_star" size="22" />
						</view>

						<view class="index">
							<text>财富指数:</text>
							<uni-rate readonly touchable :value="Daydata.money_star" size="22" />
						</view>
					</view>
					<view class="round">
						<view class="roundmin">
							<text class="fenshu">{{Daydata.lucky_num}}</text>
							<text class="day">幸运数字</text>
						</view>
					</view>
				</view>

				<view class="bottom">
					<view class="health">
						运势简评:<text>{{Daydata.general_txt}}</text>
					</view>
					<view class="supei">
						<view class="left">速配星座:<text>{{Daydata.grxz}}</text></view>
						<view class="right">幸运颜色:<text>{{Daydata.lucky_color}}</text></view>
					</view>


				</view>

			</view>

		</view>

		<view class="select">
			<common-title>
				<template #name> 每日推荐</template>
				<template #custom>
					<view class="date">
						<uni-icons type="calendar" size="18"></uni-icons>
						<view class="text"><uni-dateformat :date="Date.now()" format="dd日"></uni-dateformat></view>

					</view>
				</template>
			</common-title>
			<view class="content">
				<scroll-view scroll-x>
					<view class="box" v-for="item in randomList " :key="item._id" @click="goPreview(item._id)">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>

		<view class="theme">
			<common-title>
				<template #name> 专题精选</template>
				<template #custom>
					<navigator url="/pages/classify/classify" open-type="reLaunch" class="more"> More+</navigator>
				</template>
			</common-title>

			<view class="content">
				<theme-item v-for="item in ClassList" :key="item._id" :item="item"></theme-item>
				<theme-item :isMore="true"></theme-item>
			</view>

		</view>

	</view>
</template>

<script setup>
	import {
		apiData,
		apiWallNews,
		apiRandomWall,
		apiClassify,
		getHoroscopeList
	} from "@/api/apis.js";

	import {
		onMounted,
		ref
	} from 'vue'
	import {
		onShareAppMessage,
		onShareTimeline
	} from '@dcloudio/uni-app'
	const bannerList = ref([])
	const wallNewsList = ref([{
			"title": "悦好运壁纸，版权公告"
		},
		{
			"title": "本项目，只用于学习，无商业用途"
		},
		{
			"title": "如有侵权，请联系我删除"
		},
	])
	const randomList = ref([])
	const ClassList = ref([])

	const list = ref({
		date: ''
	})

	const horoscopeDay = ref({})
	const Daydata = ref({})

	onMounted(() => {

		getHoroscopeData()
		getData()
		getRandomWall()
		getClass()

	})

	const getHoroscopeData = async () => {
		const date = new Date();
		const month = date.getMonth() + 1; // 月份从 0 开始，所以需要加 1
		const day = date.getDate();
		const result = (month < 10 ? '0' : '') + month.toString() + (day < 10 ? '0' : '') + day.toString();
		console.log(result)
		list.value.date = result.toString()
		const res = await getHoroscopeList(list.value)
		console.log(res)
		if (res.showapi_res_body.ret_code === 0) {
			horoscopeDay.value = res.showapi_res_body
			Daydata.value = res.showapi_res_body.day
			console.log(horoscopeDay.value)
		}
	}


	//获取轮播
	const getData = async () => {
		uni.showLoading({
			title: "加载中"
		})
		const res = await apiData()
		if (res.errCode === 0) {
			bannerList.value = res.data
			uni.hideLoading();
		}


	}


	// //获取公告
	// const getNewsList = () => {
	// 	apiWallNews({
	// 		select: true
	// 	}).then(res => {
	// 		console.log(res, "公告")
	// 		if (res.errCode === 0) {
	// 			wallNewsList.value = res.data
	// 		}
	// 	})
	// }


	//随机获取9张
	const getRandomWall = () => {
		apiRandomWall().then(res => {
			console.log(res, "随机")
			if (res.errCode === 0) {
				randomList.value = res.data
			}
		})
	}

	//获取分类
	const getClass = async () => {
		const res = await apiClassify({
			select: true
		})
		console.log(res, "分类")
		res.data.splice(1, 1).concat(res.data.splice(2, 1));
		ClassList.value = res.data

	}

	//跳转
	const goPreview = (id) => {
		uni.setStorageSync("storgClassList", randomList.value)
		uni.navigateTo({
			url: "/pages/preview/preview?id=" + id
		})
	}

	//分享好友
	onShareAppMessage((e) => {
		console.log(e)
		return {
			title: "悦好运壁纸",
			path: "/pages/index/index"
		}
	})

	//分享朋友圈
	onShareTimeline(() => {
		return {
			title: "悦好运壁纸",

		}
	})
</script>

<style lang="scss" scoped>
	.Layout {

		.banner {
			width: 750rpx;
			padding: 30rpx 0;

			swiper {
				width: 750rpx;
				height: 340rpx;

				&-item {
					width: 100%;
					height: 100%;
					padding: 0 30rpx;

					.like {
						width: 100%;
						height: 100%;

						image {
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}
					}

				}
			}
		}

		.notice {
			width: 690rpx;
			height: 80rpx;
			background-color: #f9f9f9;
			margin: 0 auto;
			border-radius: 80rpx;
			display: flex;
			line-height: 80rpx;

			.left {
				width: 140rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				//穿透 
				:deep() {
					.uni-icons {
						color: $brand-theme-color !important; //最高权限 h5
					}
				}


				.text {
					color: $brand-theme-color;
					font-weight: 600;
					font-size: 28rpx
				}
			}

			.center {
				flex: 1;

				swiper {
					height: 100%;

					&-item {
						height: 100%;
						font-size: 30rpx;
						color: #666;
						overflow: hidden; //字体溢出不换行
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}
			}

			.rigth {
				width: 70rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}


		}

		.horoscope {
			padding-top: 50rpx;

			.date {
				color: $brand-theme-color;
				display: flex;
				align-items: center;


				//穿透 
				:deep() {
					.uni-icons {
						color: $brand-theme-color !important; //最高权限 h5
					}
				}

				.text {
					margin: 5rpx;
				}
			}

			.content {
				margin-top: 30rpx;
				padding: 0 20rpx;
				background-color: #f9f9f9;
				margin: 0 auto;
				border-radius: 20rpx;
				width: 690rpx;

				.fortune {
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 40rpx;
					color: #1d92c8;
				}

				.exponent {
					padding: 0 10rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.synthe {
						margin-right: 30rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						flex-direction: column; //换行

						.index {
							display: flex;

							text {
								margin-right: 10rpx;
							}
						}
					}

					.round {
						display: flex;
						justify-content: center;
						align-items: center;
						padding: 0 10rpx;
						width: 160rpx;
						height: 160rpx;
						border-radius: 50%;
						background-color: #aaaaff;

						.roundmin {
							width: 130rpx;
							height: 130rpx;
							border-radius: 50%;
							background-color: #0055ff;
							display: flex;
							justify-content: center;
							align-items: center;
							flex-direction: column; //换行

							.fenshu {
								color: #fff;
								font-size: 60rpx;
								font-weight: bold;
							}

							.day {
								color: #fff;
								font-size: 20rpx
							}
						}

					}
				}

				.bottom {
					padding: 0 10rpx;


					.health {
						margin-bottom: 30rpx;

						text {
							font-size: 28rpx
						}
					}

					.supei {
						padding-bottom: 20rpx;
						display: flex;
						justify-content: space-between;

						.left {

							font-size: 28rpx;

							text {
								color: #00ffff;
								font-size: 40rpx;
								margin-left: 30rpx;
							}
						}


						.right {

							font-size: 28rpx;

							text {
								color: #55ff00;
								font-size: 40rpx;
								margin-left: 30rpx;
							}
						}

					}
				}


			}

		}

		.select {
			padding-top: 50rpx;

			.date {
				color: $brand-theme-color;
				display: flex;
				align-items: center;

				//穿透 
				:deep() {
					.uni-icons {
						color: $brand-theme-color !important; //最高权限 h5
					}
				}

				.text {
					margin: 5rpx;
				}
			}

			.content {
				width: 720rpx;
				margin-left: 30rpx;
				margin-top: 30rpx;

				scroll-view {
					white-space: nowrap;

					.box {
						width: 220rpx;
						height: 430rpx;
						display: inline-block; //显示一行
						margin-right: 15rpx;

						image {
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}
					}

					.box:last-child {
						margin-right: 30rpx; //最后一个让两边都一样
					}
				}
			}
		}

		.theme {
			padding: 50rpx 0;

			.more {
				font-size: 32rpx;
				color: #000;
			}

			.content {
				margin-top: 30rpx;
				padding: 0 30rpx;
				display: grid; //grid 布局
				gap: 15rpx; //距离15
				grid-template-columns: repeat(3, 1fr); //一行占几个
			}
		}
	}
</style>